package homework;

public class Homework38 {
    public boolean isSubStructure(TreeNode A, TreeNode B) {
        if(A==null&&B!=null){
            return false;
        }
        if(A!=null&&B==null){
            return false;
        }
        if(B==null){
            return true;
        }
        if(A.val==B.val){
            if(isseem(A,B)==true){
                return true;
            }
        }
        return isSubStructure(A.left,B)||isSubStructure(A.right,B);
    }

    private boolean isseem(TreeNode a, TreeNode b) {

        if(a==null&&b!=null){
            return false;
        }
        if(b==null){
            return true;
        }
        if(a.val!=b.val){
            return false;
        }
        return isseem(a.right,b.right)&&isseem(a.left,b.left);
    }
}
